package com.scf.contract.controller;

import com.scf.contract.entity.PageBean;
import com.scf.contract.entity.Preloan;
import com.scf.contract.service.PreloanService;
import com.scf.uitl.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-25-11:08
 */
@RestController
@RequestMapping("/preloan")
public class PreloanController {
    @Resource
    PreloanService preloanService;

    @GetMapping("/selectAll")
    public ResponseResult selectAll(Integer pageIndex, Integer pageSize){
        List<Preloan> preloans = preloanService.selectAll(pageIndex,pageSize);
        Integer selectCount = preloanService.selectCount();
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(200);
        PageBean<Preloan> pageBean=new PageBean<>();
        pageBean.setBeanList(preloans);
        pageBean.setPageBegin(pageIndex);
        pageBean.setPageEnd(pageSize);
        pageBean.setTotalRecord(selectCount);

        responseResult.setData(pageBean);
        return responseResult;
    }

    @GetMapping("/selectByname")
    public ResponseResult selectByname(String plname,String plnaumber) {
        List<Preloan> preloans = preloanService.selectByname(plname, plnaumber);
        ResponseResult resposeResult=new ResponseResult();
        resposeResult.setCode(200);
        resposeResult.setData(preloans);
        return resposeResult;
    }
}
